package com.jpc.musicdelightapplication.ui.square.detail

import android.annotation.SuppressLint
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.jpc.lib_base.utils.LogUtil
import com.jpc.musicdelightapplication.R
import com.jpc.musicdelightapplication.data.bean.PlaylistData
import com.jpc.musicdelightapplication.data.bean.SongData
import com.jpc.musicdelightapplication.databinding.ItemPlaylistSongBinding
import com.jpc.musicdelightapplication.ext.getSimpleArtist

private const val TAG = "ItemPlaylistSongAdapter"
class ItemPlaylistSongAdapter :
    BaseQuickAdapter<SongData, BaseDataBindingHolder<ItemPlaylistSongBinding>>(
        R.layout.item_playlist_song
    ) {
    init {
        setAnimationWithDefault(AnimationType.SlideInBottom)
    }

    @SuppressLint("SetTextI18n")
    override fun convert(
        holder: BaseDataBindingHolder<ItemPlaylistSongBinding>,
        item: SongData
    ) {
        holder.dataBinding?.apply {
            val position = getItemPosition(item)
            tvIndex.text = "${position + 1}"
            tvTitle.text = item.name
            tvSubTitle.text = buildString {
                append(item.getSimpleArtist())
                append(" - ")
                append(item.al.name)
                item.originSongSimpleData?.let { originSong ->
                    append(" | 原唱: ")
                    append(originSong.artists.joinToString("/") { it.name })
                }
            }
            LogUtil.d(TAG, tvTitle.text.toString())
            executePendingBindings()
        }
    }
}